<template>
  <ul class="dynamic-box">
    <li v-for="item in arr" :key="item.id">
      <img :src="item.user.avatarUrl" class="avatarUrl" alt="" />
      <div class="item-right">
        <p class="username">{{ item.user.nickname }}</p>
        <p class="time">{{ item.showTime | fmtDate("hh:mm") }}</p>
        <p class="msg">{{ item.json.msg }}</p>
        <div class="content-box" v-if="item.json.song">
          <img
            class="picUrl"
            :src="
              item.json.song &&
              item.json.song.album &&
              item.json.song.album.picUrl
            "
            alt=""
          />
          <div>
            <p class="song-name">{{ item.json.song && item.json.song.name }}</p>
            <p class="artists">
              <span
                v-for="item in item.json.song && item.json.song.artists"
                :key="item.id"
                >{{ item.name }}</span
              >
            </p>
          </div>
        </div>
        <img
          :src="itemImg.originUrl"
          class="originUrl"
          v-for="itemImg in item.pics"
          :key="itemImg.originUrl"
          alt=""
        />
        <div class="content-box" v-if="item.json.program">
          <img
            class="picUrl"
            :src="item.json.program && item.json.program.coverUrl"
            alt=""
          />
          <div>
            <p class="song-name">
              {{ item.json.program && item.json.program.name }}
            </p>
            <p class="artists">
              {{ item.json.program && item.json.program.dj.brand }}
            </p>
          </div>
        </div>
      </div>
    </li>
  </ul>
</template>

<script>
import { dynamic } from "@/api";
export default {
  data() {
    return {
      arr: [],
    };
  },
  created() {
    this.getData();
  },
  methods: {
    getData() {
      dynamic().then((res) => {
        this.arr = res.event.map((item) => {
          item.json = JSON.parse(item.json);
          return item;
        });
      });
    },
  },
};
</script>

<style lang="scss" scoped>
.dynamic-box {
  li {
    display: flex;
    padding: 20px 0;
    border-bottom: 1px solid #e8e8e9;
    .avatarUrl {
      width: 45px;
      height: 45px;
      margin-right: 10px;
    }
    .item-right {
      flex: 1;
      .username {
        color: #0c73c2;
        font-size: 14px;
      }
      .time {
        color: #999;
        font-size: 12px;
      }
      .msg {
        font-size: 14px;
        color: #333;
        margin-top: 10px;
      }
      .content-box {
        background: #f5f5f5;
        padding: 10px;
        margin: 4px 0 5px;
        display: flex;
        .artists {
          color: #666;
          font-size: 12px;
          margin-top: 5px;
        }
        .song-name {
          color: #333;
          font-size: 14px;
        }
        .picUrl {
          margin-right: 10px;
          width: 40px;
          height: 40px;
        }
      }
      .originUrl {
        min-width: 170px;
        max-height: 338px;
      }
    }
  }
}
</style>